package com.sky.mapper.admin;

import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    /**
     * 修改分类
     * @param category
     */
     @AutoFill(value = OperationType.UPDATE)
    void update(Category category);

    /**
     * 新增分类
     * @param category
     */
    @Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
            "values(#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
     @AutoFill(value = OperationType.INSERT)
    void insert(Category category);

    /**
     * 分页查询
     * @param categoryPageQueryDTO
     * @return
     */
    List<Category> selectPage(CategoryPageQueryDTO categoryPageQueryDTO);

    /**
     * 修改状态
     * @param category
     *
     */
    @Update("update category set status = #{status},update_time=#{updateTime} ,update_user=#{updateUser} where id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void updateStatus(Category category);

    /**
     * 根据类型查询
     * @param type
     * @return
     */
    @Select("select * from category where type = #{type}")
    List<Category> selectByType(Integer type);

    /**
     * 根据id删除
     * @param id
     */
    @Delete("delete from category where id = #{id}")
    void deleteById(Long id);
}
